home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / v3 / cmplib_s.lha / cmplib_src / $procclp1.P < prev    next >
Text File  |  1990-04-12  |  3KB  |  79 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24. /* $procclp1.P */
  25.  
  26. /* procclp([St|Clp]) processes the symbol table and determines where to
  27. allocate variables and which are temporary and cetera.  It has an entry for
  28. each variable in the program, and it fills in the pragma information.  It
  29. does not fill in pragma information for the first occurrence of a variable.
  30. That is determined by the translator.  These procedures are rather simple
  31. and could be improved */ 
  32.  
  33. /* **********************************************************************
  34. $procclp1_export([$procclp/2,$getnumlits/3]).
  35.  
  36. $procclp1_use($procvars1,[$procvars/2]).
  37. $procclp1_use($alloctvars1,[$alloc_tvars/3]).
  38. $procclp1_use($computil1,[_,_,_,_,_,_,_,_,_,_,_,$check_type/2,_,_,_,
  39.                 $misc/2,_,_,_,_]).
  40. $procclp1_use($listutil1,[_,_,_,_,_,_,_,$closetail/1]).
  41. $procclp1_use($blist,[_,_,$member1/2]).
  42. ********************************************************************** */
  43.  
  44. $procclp([st(Clist,Vlist)|Clp],LastGoals) :- 
  45.     $getnumlits(Clist,0,Numlits),
  46.     $procvars(Vlist,Numlits),
  47.     $alloc_tvars(Vlist,st(Clist,Vlist),LastGoals),
  48.     $procclp_closeocclist_tails(Vlist),
  49.     !.
  50.  
  51. /*  "$getnumlits" computes the number of literals: it simply runs down the
  52.      list of literals, and returns the max. literal number. This is necessary
  53.      because inline predicates also have entries into the list of literals,
  54.      but they have to be ignored when counting the number of chunks.      */
  55.  
  56. $getnumlits([],N,N).
  57. $getnumlits([c(L,_,_)|CRest],M,N) :-
  58.     ((L > M, M1 is L) ;
  59.      (L =< M, M1 is M)
  60.     ),
  61.     $getnumlits(CRest,M1,N).
  62.  
  63. $procclp_closeocclist_tails([]).
  64. $procclp_closeocclist_tails([v(_,Occlist)|VRest]) :-
  65.     $procclp_closelelts(Occlist),
  66.     $procclp_closeocclist_tails(VRest).
  67.  
  68. $procclp_closelelts([]).
  69. $procclp_closelelts([o(_,_,_,_,_,P)|ORest]) :-
  70.     $misc(P,Misc), $closetail(Misc),
  71.     (($check_type(P,t),
  72.       $member1(use(Uselist),Misc), $closetail(Uselist),
  73.       $member1(nouse(Nouselist),Misc), $closetail(Nouselist)) ;
  74.      true
  75.     ),
  76.     $procclp_closelelts(ORest).
  77.  
  78. /* end $procclp1.P **********************************************/
  79.